package com.zmzncs.lmtc.module.customer.controller;


import com.google.common.collect.Maps;
import com.zmzncs.lmtc.common.pojo.LoginUser;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.JwtUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.customer.pojo.ticket.CustTicketDTO;
import com.zmzncs.lmtc.module.customer.pojo.ticket.CustTicketForm;
import com.zmzncs.lmtc.module.customer.pojo.ticket.CustTicketVO;
import com.zmzncs.lmtc.module.customer.service.CustTicketService;
import com.zmzncs.lmtc.module.promotion.pojo.ticket.Ticket;
import com.zmzncs.lmtc.module.promotion.pojo.ticket.TicketDTO;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JD
 * @since 2020-10-09
 */
@Api(tags = "用户-优惠券")
@RestController
@RequestMapping("/customer/ticket")
@Validated
public class CustTicketController {

    @Autowired
    CustTicketService custTicketService;


    @ApiOperation(value = "领取停车券")
    @PostMapping(value = "/receive-park-ticket")
    public Rest receiveParkTicket(@RequestParam Long parkTicketSetId) {
        custTicketService.receiveParkTicket(parkTicketSetId);

        return RestUtil.success();
    }


    @ApiOperation(value = "领取优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "/receive-ticket")
    public Rest receiveTicket(@RequestParam Long ticketId) {
        custTicketService.receiveTicket(ticketId);

        return RestUtil.success();
    }

    @ApiOperation(value = "使用优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "/getDiscountAmontWithTicket")
    public Rest<CustTicketVO> getDiscountAmontWithTicket(@Validated CustTicketForm custTicketForm) {
        CustTicketVO custTicketVo = custTicketService.getDiscountAmontWithTicket(custTicketForm);

        return RestUtil.success(custTicketVo);
    }

    @ApiOperation(value = "查询-需要首页提醒的优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "customerId", value = "用户Id", required = true),
    })
    @PostMapping(value = "getTipsTicket")
    public Rest<List<CustTicketVO>> getTipsTicket(@NotNull Long customerId) {
        List<CustTicketDTO> ticketDTOS = custTicketService.getTipsTicket(customerId);
        List<CustTicketVO> custTicketVOList = JsonUtil.listTransform(ticketDTOS, CustTicketVO.class);

        return RestUtil.success(custTicketVOList);
    }

    @ApiOperation(value = "获取用户当前可用的优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "cardType", value = "使用类型（1：停车场通用，2：时长，3：月租，4：充值，10：商品通用）", required = true),
            @ApiImplicitParam(name = "amount", value = "金额", required = true),
            @ApiImplicitParam(name = "goodsId", value = "商品Id", required = false),
    })
    @PostMapping(value = "getNotExpiredValidTicket")
    public Rest<List<CustTicketVO>> getNotExpiredValidTicket(@NotNull Integer cardType, @NotBlank String amount,Long goodsId) {
        List<CustTicketDTO> ticketDTOS = custTicketService.getNotExpiredValidTicket(cardType, amount,goodsId);
        List<CustTicketVO> custTicketVOList = JsonUtil.listTransform(ticketDTOS, CustTicketVO.class);

        return RestUtil.success(custTicketVOList);
    }

    @ApiOperation(value = "获取用户分类的优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "getItemTicket")
    public Rest getItemTicket() {
        Map map = Maps.newHashMap();
        /** 查询未使用   **/
        List<CustTicketDTO>  notExpiredTicketDTOS = custTicketService.getNotExpiredTicket();
        /** -查询-已使用**/
        List<CustTicketDTO>  usedTicketDTOS = custTicketService.getUsedTicket();
        /** 查询-已过期  **/
        List<CustTicketDTO>  expireTicketDTOS = custTicketService.getExpireTicket();
        map.put("notExpiredTicketDTOS",notExpiredTicketDTOS);
        map.put("usedTicketDTOS",usedTicketDTOS);
        map.put("expireTicketDTOS",expireTicketDTOS);
        return RestUtil.success(map);
    }





}

